package cn.tedu.restaurant.service.impl;

import cn.tedu.restaurant.entity.Order;
import cn.tedu.restaurant.mapper.OrderMapper;
import cn.tedu.restaurant.service.OrderService;
import cn.tedu.restaurant.service.exception.InsertException;
import cn.tedu.restaurant.vo.OrderVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JachinLin
 * @since 2020-10-05
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    @Resource
    private OrderMapper orderMapper;

    @Override
    public void insertOrder(Integer uid,Integer id,String time, Integer orderSeat, Integer orderNum, String phone, String username, String text)
        throws InsertException {
        Order order = new Order();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            order.setOrderTime(sf.parse(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        order.setOrderPhone(phone);
        order.setOrderSeat(orderSeat);
        order.setOrderNum(orderNum);
        order.setOrderName(username);
        order.setUid(uid);
        order.setId(id);

        order.setCreatedTime(new Date());
        order.setCreatedUser(username);
        order.setModifiedTime(new Date());
        order.setModifiedUser(username);
        orderMapper.insert(order);
    }

    @Override public List<Order> getOrders(Integer uid) {
        return orderMapper.selectAllOrders(uid);
    }

    @Override public Integer getCount() {
        return orderMapper.getCount();
    }

    @Override public List<OrderVo> getUserOrders(Integer uid) {
        return orderMapper.selectNOrder(uid);
    }
}
